package goleetcode


func numberOfPairs2(nums1 []int, nums2 []int, k int) int64 {
	mp1 := make(map[int]int)
	mp2 := make(map[int]int)
	
	max_1 := 0
	for _, num := range nums1 {
		mp1[num]++
		if num > max_1 {
			max_1 = num
		}
	}

	for _, num := range nums2 {
		mp2[num]++
	}
	
	var res int64
	
	for a, cnt := range mp2 {
		for b := a * k; b <= max_1; b += a * k {
			if _, ok := mp1[b]; ok {
				res += int64(mp1[b] * cnt)
			}
		}
	}

	return res
}